通过在java main函数中执行spring的代码 发表于 2017-02-06 | 分类于 Spring | 1234567891011121314public class Main { public static void main(String[] args) throws InterruptedException { GenericXmlApplicationContext context = new GenericXmlApplicationContext(); context.setValidating(false); context.load("classpath*:applicationContext*.xml"); context.refresh(); UserService userService = context.getBean(UserService.class); while (true) { System.out.println(userService.findUser()); Thread.sleep(10000); } }} 1234567import org.springframework.stereotype.Service;@Servicepublic class UserService { public String findUser() { return "javaniu"; }}